package com.alm.token.ui.fragmentDialog;

import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.alm.token.R;
import com.alm.token.ui.data.bean.UserWalletData;
import com.alm.token.utils.EmptyUtils;
import com.alm.token.utils.LanguageUtils;

/**
 * 作者：
 * 时间： 2017/9/18
 * 描述：    测试1
 */

public class CandyDialogFragment extends BaseDialogFragment {

    private TextView tvSure,tvContent,tvTitle;
    ClickListener clickListener;
    UserWalletData.DataBean.UserMsgBean userMsgBean;
    @Override
    protected int getLayoutId() {
        return R.layout.view_candydialog;
    }

    @Override
    protected void initView(Dialog dialog) {
        tvSure = (TextView) dialog.findViewById(R.id.tv_sure);
        tvTitle=dialog.findViewById(R.id.tv_title);
        tvContent=dialog.findViewById(R.id.tv_content);

        userMsgBean= (UserWalletData.DataBean.UserMsgBean) getDialogBean().getT();

        tvTitle.setText(LanguageUtils.getSetIndex()==1?userMsgBean.getTitle():userMsgBean.getEnTitle());
        tvContent.setText(LanguageUtils.getSetIndex()==1?userMsgBean.getContent():userMsgBean.getEnContent());

       String type= getDialogBean().getDialogType();
       if(EmptyUtils.isNotEmpty(type)&&type.equalsIgnoreCase("eggroal")){//超蛋规则弹窗
           tvSure.setText(getString(R.string.common_ok));
       }

        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(clickListener!=null){
                    clickListener.Listener("",0);
                }
                dismissParent();
            }
        });
    }


    @Override
    public int setThemeRes() {
        return R.style.BottomDialogFragment1;
    }

    private boolean outSidedismiss = true;

    @Override
    protected void setView() {
        dialog.setCanceledOnTouchOutside(outSidedismiss);
        final Window window = dialog.getWindow();
        final WindowManager.LayoutParams lp = window.getAttributes();
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.gravity = Gravity.CENTER;

        window.setAttributes(lp);
        if (!outSidedismiss) {
            getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    return keyCode == KeyEvent.KEYCODE_BACK;
                }
            });
        }
    }
    public void setListener(ClickListener clickListener) {
        this.clickListener=clickListener;
    }
    public interface ClickListener {
        void Listener(String name, int potion);
    }
}